function cicaarwrite(filename,X,endian)
% CICAARWRITE
%
%    cicaarwrite(filename,X) 
%    cicaarwrite(filename,X,endian)
%
% inputs:
% 
%   filename : name of the file to write
%          X : data matrix
%     endian : is either 'l' for little endian eg. INTEL
%                        'b' for big endian    eg. SUN SPARC
%                        'n' for machine default (default)
%
% Copyright: Mads Dyrholm, 2007
if nargin<3
  endian = 'n'
end
elms = prod(size(X))
hdr(1) = size(X,1);
hdr(2) = size(X,2);
hdr(3) = 0;
hdr(4) = 0;
hdr(5) = 0;
hdr(6) = 0;
hdr(7) = 0;
hdr(8) = 0;
hdr(9) = 0;
hdr(10) = 0;
[fid,msg] = fopen(filename,'w',endian);
fwrite(fid,10*4,'int');
fwrite(fid,hdr,'int');
fwrite(fid,10*4,'int');
fwrite(fid,elms*8,'int');
fwrite(fid,X,'real*8');
fwrite(fid,elms*8,'int');
fclose(fid);
